#include "StdAfx.h"
#include "MPanel.h"

namespace gui {

//MPanel::MPanel(void)
//{
//}
//
//MPanel::~MPanel(void)
//{
//
//}
/** Update this component */
void MPanel::Update( long dt )
{
    m_animation.Update( dt );

    // now draw all sub components
    gui::Component::Update( dt );
}

/** Render the panel */
void MPanel::Render( IRender* r )
{
    Vector3f bg = GetBackgroundColor();
    int width = GetWidth();
    int height = GetHeight();
    // set background color
    r->SetColor( bg.GetX(), bg.GetY(), bg.GetZ(), GetAlpha() );

    Vector2f pos = GetLocation();
    r->FillRect( pos.x, pos.y, width, height );

    if ( !m_images.empty() )
    {
        Image currentImage = m_images[ m_animation.GetFrame()-1 ];
        if ( currentImage.width > width ) width = currentImage.width;
        if ( currentImage.height > height ) height = currentImage.height;
        // draw the image
        r->DrawImage( &currentImage , pos.x, pos.y, width, height  );
    }
    // now draw all sub components
    gui::Component::Render( r );
}

};